<template>
  <a-card :bordered='false'>
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' @keyup.enter.native='searchQuery'>
        <a-row :gutter='24'>

          <a-col :md='6' :sm='12'>
            <a-form-item label='货品名称'>
              <a-input placeholder='请输入货品名称查询' v-model='queryParam.motorPartName'></a-input>
            </a-form-item>
          </a-col>
          <a-col :md='6' :sm='12'>
            <a-form-item label='货品编号'>
              <a-input placeholder='请输入货品编号查询' v-model='queryParam.partNo'></a-input>
            </a-form-item>
          </a-col>

          <a-col :md='12' :sm='12'>
            <a-form-item label='单据编号'>
              <a-input placeholder='请输入单据编号查询' v-model='queryParam.billNo'></a-input>
            </a-form-item>
          </a-col>


          <a-col :md='6' :sm='8'>
            <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
              <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>
              <a @click='handleToggleSearch' style='margin-left: 8px'>
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class='table-operator' style='border-top: 5px'>
      <a-button type='primary' icon='download' :loading='downloadLoading' @click="handleExportXls('货品信息')">导出</a-button>
      <a-dropdown v-if='selectedRowKeys.length > 0'>
        <a-menu slot='overlay' @click='handleMenuClick'>
          <a-menu-item key='1'>
            <a-icon type='delete' @click='batchDel' />
            删除
          </a-menu-item>
        </a-menu>
        <a-button style='margin-left: 8px'>
          批量操作
          <a-icon type='down' />
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class='ant-alert ant-alert-info' style='margin-bottom: 16px;'>
        <i class='anticon anticon-info-circle ant-alert-icon'></i>已选择&nbsp;<a style='font-weight: 600'>{{
          selectedRowKeys.length
        }}</a>项&nbsp;&nbsp;
        <a style='margin-left: 24px' @click='onClearSelected'>清空</a>
      </div>

      <a-table
        ref='table'
        bordered
        size='middle'
        rowKey='id'
        :scroll='{ x: 2000 }'
        :columns='columns'
        :dataSource='dataSource'
        :pagination='ipagination'
        :loading='loading'
        :rowSelection='{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}'
        @change='handleTableChange'>

        <span slot='tags' slot-scope='text, record'>
                 <a-tag color='geekblue'>
                  {{ handlerTags(text) }}
                 </a-tag>
          </span>

        <span slot='filePreview' slot-scope='text, record'>
                 <a-button
                   type="primary"
                   @click='previewAtta(record)'
                 >
                预览附件
              </a-button>
        </span>


        <span slot='action' slot-scope='text, record'>

          <a-dropdown>
            <a class='ant-dropdown-link'>
              更多 <a-icon type='down' />
            </a>
            <a-menu slot='overlay'>
              <a-menu-item>
                <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)'>
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

  <atta-image-model ref='previewImageModal'></atta-image-model>

  </a-card>


</template>

<script>
import { ListMixin } from '@/mixins/ListMixin'
import AttaImageModel from '../mgr-resource/modules/AttaImageModel'

export default {
  name: 'WarehouseRecordList',
  mixins: [ListMixin],
  components: {
    AttaImageModel
  },
  data() {
    return {
      description: '这是出入库台账页面',
      queryParam: {},
      columns: [
        {
          title: '单据编号',
          align: 'center',
          dataIndex: 'billNo',
          width: 120,
          sorter: true,
          fixed: true
        },
        {
          title: '关联货物',
          align: 'center',
          scopedSlots: { customRender: 'tags' },
          dataIndex: 'motorPartName'
        },
        {
          title: '货品编号',
          align: 'center',
          dataIndex: 'partNo'
        },
        {
          title: '原有库存数量',
          align: 'center',
          dataIndex: 'originalSum',
          sorter: true
        },

        {
          title: '入库数量',
          align: 'center',
          dataIndex: 'warehouseInNum',
          sorter: true
        },
        {
          title: '出库数量',
          align: 'center',
          dataIndex: 'warehouseOutNum',
          sorter: true
        },
        {
          title: '货物流向',
          align: 'center',
          dataIndex: 'partFlow'
        },
        {
          title: '责任人姓名',
          align: 'center',
          dataIndex: 'principalName'
        },
        {
          title: '变更时间',
          align: 'center',
          dataIndex: 'updateTime'
        },
        {
          title: '附件信息',
          align: 'center',
          dataIndex: 'attaIds',
          ellipsis: true,
          sorter: false,
          scopedSlots: { customRender: 'filePreview' },
        },
        {
          title: '操作',
          scopedSlots: { customRender: 'action' },
          align: 'center',
          fixed: 'right',
          width: 170
        }

      ],
      url: {
        list: '/motorfactory/warehouse-record/list',
        delete: '/motorfactory/warehouse-record/delete',
        deleteBatch: '/motorfactory/warehouse-record/deleteBatch'
      }
    }
  },
  computed: {},
  methods: {
    handlerTags(item) {
      return item
    },
    handleMenuClick(e) {
      if (e.key == 1) {
        this.batchDel()
      } else if (e.key == 2) {
        this.batchFrozen(2)
      } else if (e.key == 3) {
        this.batchFrozen(1)
      }
    },

    previewAtta(record) {
      this.$refs.previewImageModal.showModal(record)
    }
  }

}
</script>